<template>
    <div>
        <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item', item.id ===0? 'mui-active':'']" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="item in photosList" :key="item.id" @click="getimgages(item.id)">
							{{item.title}}                           
						</a>
                        
					</div>
				</div>
            </div>  
            <!-- <ul class="images-ul">
                <li v-for="item in img" :key="item.id">
                    <img v-lazy="item.img_url">
                </li>
            </ul>   -->

            <!-- 放置接受图片 -->
         <ul class="images-ul">
             <!-- 这一步是为了向子组件传送点击的id值，'10'+'5'=='105' -->
                <router-link v-for="item in img" :key="item.id" :to="'/home/photoinfo?id='+'10'+item.id" tag="li">
                    <img :src="item.img_url">
                    <div class="title-zy">
                        <p>{{ item.title }}</p>
                        <div class="zy">{{ item.zhaiyao }}</div>
                    </div>
                </router-link>
        </ul> 
    </div>
</template>

<script>
    //引入mui.js文件
    import mui from '../../lib/mui/js/mui.min.js'
    import { Toast } from 'mint-ui'

    
    
    export default {
        data: function(){
            return {
                photosList: [],
                img: []
            }
        },
        created: function(){
            this.getPhotosList()
            this.getimgages(0)
        },

        //这个时候页面已经创建出来了，但是还没有加载出来，所以可以在这个时候加载mui对象，等页面一加载出来就可以用
        mounted: function(){
            mui('.mui-scroll-wrapper').scroll({
	        deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            })
        },
        methods: {
            getPhotosList: function(){
                this.$http.get('http://127.0.0.1:4000/photoslist').then(function(res){
                    //console.log(res.body)
                    if(res.body.message != 'ok' || res.body.success != true){
                        return Toast('获取数据失败')
                    }
                    res.body.photoslist.unshift({id: 0, title: '全部'})
                    this.photosList = res.body.photoslist
                    // console.log(this.photosList)                   
                })
            },
            getimgages: function(id){
                this.$http.get('http://127.0.0.1:4000/getimages?id='+id).then(function(res){
                    //console.log(res)
                    if(res.body.message != 'ok' || res.body.success != true){
                        return Toast('获取数据失败')
                    }
                    this.img= res.body.img
                    console.log(this.img)
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    * {
        touch-action: pan-y;
    }
    .images-ul{
        padding: 0 10px;
        li{
            list-style: none;
            // padding: 5px 0;
            box-shadow: 3px 3px 9px #ddd;
            padding: 5px 0;
            position: relative;
            img{    
                    display: block;
                    // width: 330px;
                    width: 100%;
                    margin: auto;
                    vertical-align: middle;
                 }
            .title-zy{
                font-size: 14px;
                color: #fff;
                position: absolute;
                bottom: 0;
                left: 0;
                max-height: 88px;
                width: 100%;
                background-color: rgba(0,0,0,.4);
                p{
                    color: #fff;
                    margin: 0;
                }

            }
        }
    }
    
    
</style>